import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 新闻，房友圈，头条等列表，发布接口
 *
 * allen  2021-08-24
 */

/**
 * 查询新闻列表
 */
const queryNewsList = () => {
  return new Promise((resolve, reject) => {
    get("/user/customer/index").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 发布帖子
 * @param {*} data 
 */
const publishArticleAction = (data) => {
  return new Promise((resolve, reject) => {
    post("/dyn/push", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 帖子话题列表
 */
const queryArticleThemeList = () => {
  return new Promise((resolve, reject) => {
    get("/dyn/title/list").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 创建帖子话题
 * @param {*} title 
 */
const createArticleTheme = (title) => {
  return new Promise((resolve, reject) => {
    get("/dyn/create/title?title=" + title).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 查询发布帖子选择的楼盘列表
 */
const queryArticleHouse = (page, pageSize, words) => {
  return new Promise((resolve, reject) => {
    post("/new/house/query/all?page=" + page + "&pageSize=" + pageSize + "&words=" + words).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 查询新闻所有tags
 */
const queryArticleTags = () => {
  return new Promise((resolve, reject) => {
    get("/news/query/all/tag").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 房友圈动态列表
 * @param {*} page 
 * @param {*} pageSize 
 * @param {*} words 
 */
const queryDynList = (page, pageSize, words) => {
  return new Promise((resolve, reject) => {
    get("/dyn/list?page=" + page + "&pageSize=" + pageSize + "&words=" + words).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 获取消息未读数量
 * @param {*} type 
 *  NEW_HOUSE(1, "新房楼盘评论"),
    DYN(2, "动态评论"),
    TEAM(3, "共享评论"),
 */
const queryCommentNotRead = (type) => {
  return new Promise((resolve, reject) => {
    get("/comment/not/read?type=" + type).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 根据tag查看对应的新闻列表
 * @param {*} page 
 * @param {*} pageSize 
 * @param {*} tag 
 */
const queryNewsListByTag = (page, pageSize, tag,words) => {
  return new Promise((resolve, reject) => {
    get("/news/query/tag?page=" + page + "&pageSize=" + pageSize + "&tag=" + tag + "&words=" + words).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 根据id查询富文本文章详情
 * @param {*} id 
 */
const queryRichArticleDetail = (id) => {
  return new Promise((resolve, reject) => {
    get("/news/detail?id=" + id).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.msg)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}















module.exports = {
  queryNewsList,
  publishArticleAction,
  queryArticleThemeList,
  queryArticleHouse,
  queryArticleTags,
  queryDynList,
  queryCommentNotRead,
  createArticleTheme,
  queryNewsListByTag,
  queryRichArticleDetail,
}
